package com.coocaa.ops.admin.v1.upload.util;

/**
 * @author bijiahao
 * @date : 2019/2/15.
 * @description
 */
public class FileAnalyzerUtil {

    /**
     * 获取文件名称
     *
     * @param filePath
     * @return
     */
    public static String getOriginFileName(String filePath) {
        int pos = filePath.lastIndexOf("/");
        String fileName = filePath;
        if (pos != -1) {
            fileName = filePath.substring(pos + 1);
        }
        return fileName;
    }

    /**
     * 获取文件的后缀名
     *
     * @param originFileName
     * @return
     */
    public static String getFileExtName(String originFileName) {
        int lastPointIndex = originFileName.lastIndexOf(".");
        String extName = "";
        if (lastPointIndex != -1) {
            extName = originFileName.substring(lastPointIndex).toLowerCase();
        }
        return extName;
    }

    /**
     * 获取去掉文件类型后缀的文件名
     *
     * @param originFileName
     * @return
     */
    public static String getFileNameTrimSuffix(String originFileName) {
        int lastPointIndex = originFileName.lastIndexOf(".");
        String fileNameTrimSuffix = originFileName;
        if (lastPointIndex != -1) {
            fileNameTrimSuffix = originFileName.substring(0, lastPointIndex);
        }
        return fileNameTrimSuffix;
    }

}
